package com.zhenhao.xsq.ui.activity.user;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;
import com.zhenhao.xsq.R;
import com.zhenhao.xsq.adapter.door.DoorManageAdapter;
import com.zhenhao.xsq.adapter.user.UserListAdapter;
import com.zhenhao.xsq.application.AppConfig;
import com.zhenhao.xsq.base.BaseActivity;
import com.zhenhao.xsq.ui.activity.user.component.DaggerUserListComponent;
import com.zhenhao.xsq.ui.activity.user.contract.UserListContract;
import com.zhenhao.xsq.ui.activity.user.module.UserListModule;
import com.zhenhao.xsq.ui.activity.user.presenter.UserListPresenter;
import com.zhenhao.xsq.utils.TimeUtil;
import com.zhenhao.xsq.utils.ToastUtil;
import com.zhenhao.xsq.utils.UIUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.ButterKnife;

public class UserListActivity extends BaseActivity implements UserListContract.View {

    @BindView(R.id.bt_search)
    Button btSearch;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.srl)
    SmartRefreshLayout srl;
    private String TAG = "UserListActivity";

    @Inject
    UserListPresenter mPresenter;

    private UserListAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_user_list);
        ButterKnife.bind(this);
//        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setToolbarTitle("选择住户");

        initRv();
    }

    private void initRv() {
        UIUtils.configRecycleView(rv, new LinearLayoutManager(this));
        adapter = new UserListAdapter();
        rv.setAdapter(adapter);

        adapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                Bundle bundle = new Bundle();
                startActivity(UserCardActivity.class,bundle);
            }
        });

        srl.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                srl.finishRefresh();
                srl.resetNoMoreData();

                initData();
            }
        });
    }

    @Override
    protected void initData() {
        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("1");
        list.add("1");
        adapter.setNewData(list);
    }

    @Override
    protected void setupActivityComponent() {
        DaggerUserListComponent
                .builder()
                .appComponent(((AppConfig) getApplication()).getApplicationComponent())
                .userListModule(new UserListModule(this))
                .build()
                .inject(this);
    }

    @Override
    public void showProgressDialog() {
        progressDialog.show();
    }

    @Override
    public void closeProgressDialog() {
        progressDialog.hide();
    }

    @Override
    public void setPresenter(UserListContract.UserListContractPresenter presenter) {
        mPresenter = (UserListPresenter) presenter;
    }
}
